import Mock from 'mockjs'

const userRoleList = []
const count = 100
for (let i = 0; i < count; i++) {
  userRoleList.push(
    Mock.mock({
      id: '@increment',
      roleName: '@first',
      remark: '@first',
    })
  )
}
const user = {
  id: 1,
  username: 'admin',
  password: '123',
  token:
    'eyJhbGciOiJIUzI1NiJ9.eyJsb2dpblRpbWUiOiIyMDIxLTA4LTE4VDA5OjU2OjM1IiwiaXAiOiIxNzIuMTcxLjQ4LjExNCIsImlzcyI6ImF1dGgwIiwidXNlcklkIjoxfQ.FSYJwYjexTh8hmWVo787pOCg8CqsSkgUlKXSbXeIAY4',
  name: 'admin',
  avatar: '',
  introduction: '',
  cloudId: '',
  port: '',
  buttons: [],
  ip: '172.171.48.114',
  mode: '',
  modeSucc: '',
  roles: [],
  error: '',
  phoneNumber: 'Si8zOXJ0VmJTSjQzTnlXaXdJVFhIQT09',
  email: 'Rkh0L3BQaXF5aGwvSmxsb3o3MWFqdz09',
  licenseStatus: {
    status: 1,
    prefix: '1',
    middleMsg: '2',
    suffix: '3',
    licenseType: '',
  },
  timeoutTime: 60,
  passwordUpdated: 1,
  passwordStatus: 1,
  prefix: '',
  middleMsg: '',
  suffix: '',
  orgId: 0,
}
const userBtn = []
userBtn.push('user:view')
userBtn.push('user:add')
userBtn.push('user:batchDel')
userBtn.push('user:update')
userBtn.push('user:del')
const menuList = []
const menu1 = {
  menuType: 'M',
  children: [],
  parentId: 0,
  menuName: '系统管理',
  icon: 'xitongshezhi',
  perms: null,
  menuId: 1,
  redirect: 'noRedirect',
  path: '/system',
  hidden: 2,
  component: '#',
}
const menu2 = {
  menuType: 'M',
  children: [],
  parentId: 0,
  menuName: '告警中心',
  icon: 'xitongshezhi',
  perms: null,
  menuId: 11,
  redirect: 'noRedirect',
  path: '/system',
  hidden: 2,
  component: '#',
}
const menu1c1 = {
  menuType: 'C',
  children: [],
  parentId: 1,
  menuName: '用户管理',
  icon: '',
  perms: null,
  redirect: '',
  menuId: 2,
  path: 'user',
  hidden: 2,
  component: 'system/UserList',
}
const menu1c1b1 = {
  menuType: 'B',
  children: [],
  parentId: 2,
  menuName: '查看',
  icon: '',
  perms: null,
  redirect: '',
  menuId: 4,
  path: 'user',
  hidden: 2,
  component: '',
  authorizable: 0,
}
const menu1c1b2 = {
  menuType: 'B',
  children: [],
  parentId: 2,
  menuName: '修改',
  icon: '',
  perms: null,
  redirect: '',
  menuId: 5,
  path: 'user',
  hidden: 2,
  component: '',
}
menu1c1.children.push(menu1c1b1)
menu1c1.children.push(menu1c1b2)
const menu1c2 = {
  menuType: 'C',
  children: [],
  parentId: 1,
  menuName: '角色管理',
  icon: '',
  perms: null,
  redirect: '',
  menuId: 3,
  path: 'userRoleList',
  hidden: 2,
  component: 'system/UserRoleList',
}
const menu2c1 = {
  menuType: 'C',
  children: [],
  parentId: 11,
  menuName: '告警级别',
  icon: '',
  perms: null,
  redirect: '',
  menuId: 22,
  path: 'userRoleList',
  hidden: 2,
  component: 'system/UserRoleList',
}
menu1.children.push(menu1c1)
menu1.children.push(menu1c2)
menu2.children.push(menu2c1)
menuList.push(menu1)
menuList.push(menu2)

const userList2 = []
const userList3 = []
for (let i = 0; i < 4; i++) {
  userList2.push(
    Mock.mock({
      userId: '@increment',
      userName: '@first',
      phone: '@phone',
      email: '@phone',
    })
  )
}
for (let i = 0; i < 10; i++) {
  userList3.push(
    Mock.mock({
      userId: '@increment',
      userName: '@first',
      phone: '@phone',
      email: '@phone',
    })
  )
}
export default  [
  // user login
  {
    url: '/sysUser/login',
    type: 'post',
    response: (config) => {
      return {
        code: 1,
        data: user,
      }
    },
  },
  // user logout
  {
    url: '/login/updatePassword',
    type: 'post',
    response: (_) => {
      return {
        code: 1,
        data: 'success',
      }
    },
  },
  {
    url: '/sysMenu/getButtonPermissions',
    type: 'get',
    response: (_) => {
      return {
        code: 1,
        data: {
          roleNames: ['admin', 'editor'],
          buttonPermissions: userBtn,
        },
      }
    },
  },
  // user logout
  {
    url: '/mock/sysUser/logout',
    type: 'get',
    response: (_) => {
      return {
        code: 1,
        data: 'success',
      }
    },
  },
  {
    url: '/sysConf/getStatus',
    type: 'get',
    response: (_) => {
      return {
        code: 1,
        data: 'success',
      }
    },
  },
  {
    url: '/sysMenu/getAll2',
    type: 'get',
    response: (_) => {
      return {
        code: 1,
        data: menuList,
      }
    },
  },
  {
    url: '/gateway/confirmMessage',
    type: 'post',
    response: (_) => {
      return {
        code: 1,
        msg: '操作成功',
        data: {
          gatewayReboot: 0,
          gatewayUpgrade: 0,
          gatewayRecovery: 0,
          gatewayReset: 0,
        },
      }
    },
  },
  {
    url: '/login/userConfig',
    type: 'get',
    response: (_) => {
      return {
        code: 1,
        msg: '操作成功',
        data: {
          loginErrorNum: 10,
          loginTimeoutTime: 1,
          loginTimeoutTimeUnit: '分钟',
          ssoSwitch: 0,
          ssoMode: 2,
        },
      }
    },
  },
  {
    url: '/login/userConfig',
    type: 'post',
    response: (_) => {
      return {
        code: 1,
        data: 'success',
      }
    },
  },
  {
    url: '/sysRole/list',
    type: 'post',
    response: (config) => {
      const { page, pageSize } = config.body
      const pageList = userRoleList.filter(
        (item, index) =>
          index < pageSize * page && index >= pageSize * (page - 1)
      )

      return {
        code: 1,
        msg: '操作成功',
        data: {
          total: userRoleList.length,
          items: pageList,
        },
      }
    },
  },
  {
    url: '/UserManage/addUserRole',
    type: 'post',
    response: (_) => {
      return {
        code: 1,
        data: 'success',
      }
    },
  },
  {
    url: '/UserManage/queryUserByRole',
    type: 'post',
    response: (_) => {
      return {
        code: 1,
        data: {
          hasUser: userList2,
          unUser: userList3.concat(userList2),
        },
      }
    },
  },
  {
    url: '/UserManage/queryPageList',
    type: 'post',
    response: (_) => {
      return {
        code: 1,
        data: {
          totle: 1,
          items: [],
        },
      }
    },
  },
  {
    url: '/UserManage/delRole',
    type: 'post',
    response: (_) => {
      return {
        code: 1,
        data: 'success',
      }
    },
  },
]
